import os
import sys
import pprint
import operator
import itertools
import time

absp=os.path.abspath(__file__)
absdir=os.path.dirname(absp)
pathdir=os.path.dirname(absdir + '/../..')
sys.path.append(pathdir)

from wellfunctions import WellFunctions
import unittest

class  Wellfunctions_TestCase(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_wellfunctions_a1(self):
        """Default a"""
        wf = WellFunctions(gen=False)
        self.assertEqual(wf.a, [0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09,0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5])

    def test_wellfunctions_a2(self):
        """To set a"""
        wf = WellFunctions(a=[1.0,2.0,3.0],gen=False)
        self.assertEqual(wf.a,[1.0,2.0,3.0])

    def test_wellfunctions_u1(self):
        """To set a"""
        wf = WellFunctions(u=[1.0,2.0,3.0],gen=False)
        self.assertEqual(wf.u,[1.0,2.0,3.0])

    def test_wellfunctions_u2(self):
        """To set a"""
        wf = WellFunctions(u=[1.0,2.0,3.0],gen=True)
        self.assertEqual(wf.u,[1.0,2.0,3.0])

    def test_wellfunctions_u3(self):
        """To set a"""
        ww = WellFunctions(gen=True)
        time.sleep(4)
#        print
#        print "u=%s" % ww.u
#        print
#        print "a=%s" % ww.a
#        print
        #pprint.pprint( ww.wua_data )
        #print
        #pprint.pprint( www.wua_data_u )
        print
        print "="*10
        print ww.wua_from_dictionary(u=2.33, a=0.339)
        print ww.wua_from_dictionary(u=5, a=0.1)
        print "="*10

    def test_wellfunctions_wua_1(self):
        """To set a"""
        wf = WellFunctions(a=[0.050,0.100,0.200,0.300],u=[1.000,1.500,2.000,2.500,3.000],gen=True)
        time.sleep(4)
        #print wf.wua_data
        #print "*_@_"*20
        print
        pprint.pprint( wf.wua_data )
        print
        pprint.pprint( wf.wua_data_u )
        print
        #wf.wua_data.sort(key=operator.itemgetter('a'))
        #pprint.pprint( wf.wua_data )
        #mk=wf.wua_data.keys()
        #mk.sort()
        #for i in mk:
        #    print "a=%s" % i
        #    print "u=%s" % wf.wua_data[i]
        # u interpolate
        print
        print "="*10
        u=1.25
        a=0.10
        print "(u: %f,a: %f, wua: %f)" % ( u, a, wf.wua_from_dictionary(u=u, a=a) )
        u=1.00
        a=0.15
        print "(u: %f,a: %f, wua: %f)" % ( u, a, wf.wua_from_dictionary(u=u, a=a) )
        # u and a interpolate
        u=1.20
        a=0.25
        print "(u: %f,a: %f, wua: %f)" % ( u, a, wf.wua_from_dictionary(u=u, a=a) )
        print "="*10

    def test_wellfunctions_wua_2(self):
        """To set a"""
        wf = WellFunctions(gen=True)
        time.sleep(1)
        # u interpolate
        wf.wua_from_dictionary(u=1.25, a=55.5)
        # a interpolate
        wf.wua_from_dictionary(u=500.0, a=0.1)

if __name__ == '__main__':
    unittest.main()

